package com.somewater.controller
{
	import com.nbooo.ui.BaseMenu;
	import com.somewater.control.IClear;
	import com.somewater.game.GameModule;
	import com.somewater.storage.RoomDef;
	
	import flash.display.Sprite;

	public class MenuManager
	{
		/*
		 *	Класс управляет всеми игровыми меню (профайлы, списки игр и прочие)  
		*/
		public static var instance:MenuManager;
		
		private var _menuLayer:Sprite;
		
		public function MenuManager()
		{
			
		}
		
		public static function initialize(menuLayer:Sprite):void
		{
			if(!menuLayer)
			{
				
				CONFIG::debug
				{
					trace ("menuLayer is null ?");
				}
			}
				
			instance = new MenuManager();
			instance.setMenuLayer(menuLayer);
						
		}
		
		public static function getInstance():MenuManager
		{
			if(!instance)
				instance = new MenuManager();
			return instance;
		}
		
		public function setMenuLayer(layer:Sprite):void
		{
			this._menuLayer = layer;		
		}
		
		public function showMenu(menu:BaseMenu):void
		{
			_menuLayer.addChild(menu);
		}
		
		
		public function showGame(_roomDef:RoomDef):void
		{
			while(_menuLayer.numChildren)
				IClear(_menuLayer.removeChildAt(0)).clear();
			_menuLayer.addChild(new GameModule(_roomDef));
		}
	}
}